﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using jQueryDotNetLib.Extenders;

namespace jQueryDotNetLib.Extras.Extenders
{
    [ToolboxItem(true)]
    [ToolboxData("<{0}:QTip Selector=\"\" runat=server />")]
    public class QTip : BaseInteractionExtender
    {
        public QTip()
        {
            Interaction = "qtip";
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Content
        {
            get
            {
                if (ViewState["Content"] == null) return "";
                return (string)ViewState["Content"];
            }
            set
            {
                ViewState["Content"] = value;
            }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Position
        {
            get
            {
                if (ViewState["Position"] == null) return "center";
                return (string)ViewState["Position"];
            }
            set
            {
                ViewState["Position"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public int Width
        {
            get
            {
                if (ViewState["Width"] == null) return 250;
                return (int)ViewState["Width"];
            }
            set
            {
                ViewState["Width"] = value;
            }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string WrapperCSS
        {
            get
            {
                if (ViewState["WrapperCSS"] == null) return "";
                return (string)ViewState["WrapperCSS"];
            }
            set
            {
                ViewState["WrapperCSS"] = value;
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            base.AddParameter("content", "\"" + Content + "\"");
            base.AddParameter("position", "\"" + Position + "\"");
            
            writer.Write("<style type=\"text/css\">");
            if (WrapperCSS == "")
            {
                writer.Write("div.qtip-wrapper {");
                writer.Write("z-index: 999;");
                writer.Write("text-align: center;");
                writer.Write("position: absolute;");
                writer.Write("font-size: .9em;");
                writer.Write("width: " + Width + "px;");
                writer.Write("background: transparent url(arrow.png) no-repeat scroll center bottom;");
                writer.Write("color: #fff;");
                writer.Write("padding-bottom: 5px;");
                writer.Write("display: none");
                writer.Write("}    ");

                writer.Write("div.qtip-wrapper div {");
                writer.Write("background: #333 none;");
                writer.Write("padding: 5px;");
                writer.Write("font: normal normal .9em/1em \"Arial\", verdana, sans-serif;");
                writer.Write("}</style>");
            }
            else
            {
                writer.Write(WrapperCSS);
            }

            base.Render(writer);
        }
    }
}
